<?php

   function get_discount_action($id_goods,$basket = array(),$id_client = 0)
{
   
    //$good = get_good($id_goods);
    //$id_brand = '';
    
    //if (is_array($good))
    //{
    //    $id_brand = isset($good['id_brand'])? $good['id_brand']:'';
    //}
    
    $quantity = isset($basket['quantity'])?(int)$basket['quantity']:0;
    $summa = isset($basket['summa'])?$basket['summa']:0;
    
    
    
    
    $sql = "SELECT * FROM `spip_ecatalogue_discount_signs` t 
         JOIN spip_ecatalogue_discount_rules r ON t.id_rule = r.id_rule

          WHERE
             '".date("Y-m-d H:i:s")."' between r.date_start and r.date_end and  
           (`t`.`object`='id_goods' and `t`.`value`='".$id_goods."')";
    
    //if ($id_brand)
    //{
    //    $sql.=" OR
    //       (`t`.`object`='id_brand' and `t`.`value`='".$id_brand."') ";
    //}
    
    if ($quantity)
    {
        $sql.=" OR
           (`t`.`object`='quantity' and `t`.`value`='".$quantity."') ";
    }
    
    if ($summa)
    {
        $sql.="OR
           (`t`.`object`='summa' and `t`.`value`>='" . $summa . "')";
    }
    
            
    $sql.= " LIMIT 1 ";
    
    echo '<pre>';
    print_r($sql);
    echo '</pre>';
    
    
    
    $res_rule = sql_query($sql);
    
    $action= isset($res_rule[0]['action'])?$res_rule[0]['action']:'';   
   
    return $action;




?>